Introduction to toLocaleDateString () method in JavaScript, tolocaledatestring
The Date of the JavaScript Date. toLocaleDateString () method is converted to a string, and the "Date" section is returned using the language environment conventions of the operating system.Syntax
Date. toLocaleDateString ()
The following
This article mainly introduces how to use toLocaleDateString () in JavaScript. it is the basic knowledge in JS beginners. if you need it, refer to JavaScript Date. the date of toLocaleDateString () method is converted to a string, and the "date" section is returned using the language environment conventions of the operating system.
Syntax
Date. toLocaleDateStrin
result.Syntax:dateobject.tolocalestring ()return Value:A string representation of dateobject, expressed as a local time zone, and formatted according to local rules.Example 1In this example, we will convert today's date to a string based on local time:Output:2015/4/28 morning 10:07:15Example 2In this case, we will convert the specific date to a string based on local time:Output:1983/7/21 morning 1:15:00JavaScript tolocaletimestring () methoddefinition and Usage:the tolocaletimestring () method
This article mainly introduces how to use toLocaleDateString () in JavaScript. It is the basic knowledge in JS beginners. If you need it, refer to JavaScript Date. the date of toLocaleDateString () method is converted to a string, and the "date" section is returned using the language environment conventions of the operating system.
Syntax
Date. toLocaleDateStrin
The date of the JavaScript date.tolocaledatestring () method is converted to a string and the "date" section is returned using the conventions of the operating system's locale.Grammar
Date.tolocaledatestring ()
The following are the
formal JS code, you need to first understand the Date object in JS, through the Date object, you can get to the date of the month and a minute and time stamps and other information, specific reference: http://www.w3school.com.cn/jsref/jsref_obj_date.asp
var D1 = new Date (); Get current system time my present time is April 25, 2016 Monday
D1.getfullyear (); Obtain the year information, 2016
d1.getmonth (); Get the month information (starting from 0:0-11) 3
d1.getdate ();
= = = '/getdata ') { var arr = ' [' + ' {' title ': ' XI attended the National Science and Technology Award Conference 1 ', ' Time ': ' +new date (). tolocaledatestring () + ' "}, ' + ' {" title ":" Xi attended the National Science and Technology Award Conference 2 "," Time ":" ' +new Date ". toLocaleDateString () + ' "}, ' + ' {" title ":" Xi attended the National Science and Techn
Displaying the date and time in a specified format is very useful for developing time-related applications. Next, let's share with you how to format and display the date and time. For more information, see
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
The current time.
The Code is as follows:
// 1.2013-4-9 11:21:32// 2.2013-, January 1, April 9// April 9 11:21:32 A.M.// April 9 13:21:32 P.M./*Var thedate = new Date ();Alert (thedate. ge
JS to obtain the current date and time and other operations 2008-07-28-06-11 17: 24var mydate = new date ();Mydate. getyear (); // obtain the current year (2 digits)Mydate. getfullyear (); // obtain the complete year (4 bits, 1970 -????)Mydate. getmonth (); // obtain the current month (0-11, 0 represents January)Mydate. getdate (); // obtain the current day (1-31)Mydate. getday (); // obtain X of the current week (0-6, 0 indicates Sunday)Mydate. gettime (); // obtain the current time (millisecon
. setMinutes (30); // => 30: dt. setSeconds (40); // => 40: seconds dt. setMilliseconds (333); // => 333: console in milliseconds. log (dt); // => December 25, 2014 minutes, 40 seconds, 333 milliseconds
3.3 Other Methods
3.3.1 toString (): Convert Date to a 'year, month, day, hour, minute, second 'string
3.3.2 toLocaleString (): converts a Date to a local format string of 'Year, month, day, hour, minute, second '.
3.3.3 toDateString (): Convert Date to a 'year, month, and Day' string
3.3.4
: If you only want to display the year, onclick= "Wdatepicker ({datefmt: ' yyyy-mm ')", as Ben came here should end, but after the need to add another, said to give the start time and end time set a default time, tested, this plugin does not have the corresponding method can do.Then I thought of a method, using jquery to get the value of the start time and end time element, and then call the native JS new Date () method, and use tolocaledatestring
turned into a string. toLocaleString Date and time tolocaledatestring dateTurns a string into a Date object. A date string with the specified format--millisecond value---> Date object.var str_date = "9/28/2017";var time2 = Date.parse (str_date);var date3 = new Date (time2);println (Date3.tolocaledatestring ());//September 28, 20174. With () usage* To simplify the writing of object invocation content.* You
GMT (exact format depends on the operating system running on the computer) toLocaleString () Turns the Date object's dates (a numeric value) into a string, using the specific date format that is configured on the computer on which UTC () uses date UTC (Year, month, day, time, minute, second), since January 1, 1997 00:00:00 ( The number of milliseconds since the time, minutes, and seconds are optional to return the date1. Current system locale format (toloca
(New Date (' 2016-7-12 '). toDateString ())//tue June 2016
Console.log ( New Date (' 2016-7-12 '). totimestring ());//00:00:00 gmt+0800 (China Standard Time)
Console.log (new date (' 2016-7-12 '). Tojson ()) ;//2016-07-11t16:00:00.000z
toLocaleString ()
Localized conversion of the ToString () method
toLocaleTimeString ()
Localized conversion of the toTimeString () method
toLocaleDateString ()
Localized conversion of the toDateString () meth
(); // obtain the complete year (4 digits, 1970 -????) MyDate. getMonth (); // obtain the current month (0-11, 0 represents January) myDate. getDate (); // obtain the current day (1-31) myDate. getDay (); // obtain the current day X (0-6, 0 represents Sunday) myDate. getTime (); // obtain the current time (milliseconds starting from 1970.1.1) myDate. getHours (); // obtain the current hour (0-23) myDate. getMinutes (); // get the current number of minutes (0-59) myDate. getSeconds (); // obtain
methods in the Date object that can convert the Date into a string, which is worth mentioning. In some cases, part of the date or date needs to be converted into a string. For example, if you append it to a string or use it in a comparison statement. There are several methods available for Date objects, which provide slightly different methods to convert them into strings, including:● ToDateString● ToLocaleDateString● ToLocaleTimeString● ToLocaleStri
string representation of the date part of the date object.
ToGMTString () function -- returns the string representation of the Greenwich Mean Time (GMT) of the date object.
ToLocaleDateString function -- returns the localized string of the date part of the date object.
ToLocaleTimeString function -- returns the localized string of the time part of the date object
ToTimeString () function -- returns the time string of the date object.
ToUTCString func
Copy codeThe Code is as follows:$ (Function (){Var mydate = new Date ();Var t = mydate. toLocaleString ();/* Alert (t );*/$ ("# Time"). text (t );$ ("# Time"). load ("Untitled-1.html ");}); Use the built-in Date function to get the JavaScript time.Var mydate = new Date ();Mydate. getYear (); // obtain the current year (2 digits)Mydate. getFullYear (); // obtain the complete year (4 bits, 1970 -????)Mydate. getMonth (); // obtain the current month (0-11, 0 represents January)Mydate. getDate (); /
toLocaleString (): converts a Date to a local format string of 'Year, month, day, hour, minute, second '.
4.3.3 toDateString (): Convert Date to a 'year, month, and Day' string
4.3.4 toLocaleDateString (): converts a Date to a local string of the 'Year, month, and Day' format.
4.3.5 toTimeString (): converts a Date to a 'hour, minute, and second 'string.
4.3.6 toLocaleTimeString (): converts a Date to a local string in 'hour, minute, second 'format.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.